/*
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2024-01-25 10:25:34
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2024-01-25 17:54:38
 * @FilePath: /hr_new_vue3/src/utils/getAllListData.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/* 获取要转换的数据列表 */

import { getPositionHierarchyList } from '@/apis/management/organization/baseSetting/PositionSystem/index';
import { GetOrganizationListDetail } from '@/apis/management/organization/organizationManagement';
import {
  getPositionFlatList,
  getFlatDept,
  getAllHumanRoster,
  getPositionTypeFlatList
} from '@/utils/common';
import { GetLegalEntityList } from '@/apis/management/organization/organizationManagement/LegalEntity/index';
import { GetWorkPlaceList } from '@/apis/management/organization/organizationManagement';
import { GetJobList } from '@/apis/management/organization/positionManagement';
import { GetContractGroup } from '@/apis/management/contract/baseSetting';
import { OrganizationPatternSearch } from '@/apis/management/organization/baseSetting/organizationalType';
import { GetAllHumanChangeSetting } from '@/apis/management/human/baseSetting/humanSetting';
export type Idata = {
  humanRosterList?: []; // 人员列表
  organizationList?: []; // 组织列表
  organizationTypeList?: []; // 组织类型
  positionList?: []; // 职位列表
  positionTypeList?: []; // 职位类别列表
  positionHierarchyList?: []; // 职位层级
  jobList?: []; // 职务列表
  lawList?: []; // 法律实体列表
  workplaceList?: []; // 工作地点列表
  contractTypeList?: []; // 合同类型列表
  transactionTypeList?: []; // 异动类型列表
};

const data: Idata = {
  humanRosterList: [], // 人员列表
  organizationList: [], // 组织列表
  organizationTypeList: [], // 组织类型
  positionList: [], // 职位列表
  positionTypeList: [], // 职位类别列表
  positionHierarchyList: [], // 职位层级
  jobList: [], // 职务列表
  lawList: [], // 法律实体列表
  workplaceList: [], // 工作地点列表
  transactionTypeList: [], // 异动类型列表
  contractTypeList: [] // 合同类型列表
};

// 分页数据，默认获取全部数据
const pageParams = {
  pageNumber: 0,
  pageSize: -1
};

export type IneedSwitchArr =
  | 'organization' // 组织
  | 'organizationType' // 组织类型
  | 'human' // 人员
  | 'position' // 职位
  | 'positionType' // 职位类型
  | 'positionHierarchy' // 职位层级
  | 'job' // 职务
  | 'law' // 法律实体
  | 'workplace' // 工作地点
  | 'transactionType' // 异动类型
  | 'contractType'; // 合同类型

/**
 * 获取所有要转换数据的列表
 * @param needSwitchArr 需要转换的数据，传对应的字符串
 * */
export const getListData = async (needSwitchArr: IneedSwitchArr[]) => {
  try {
    if (needSwitchArr.includes('organization')) {
      data.organizationList = await getFlatDept();
    }
    if (needSwitchArr.includes('organizationType')) {
      data.organizationTypeList = (
        await OrganizationPatternSearch({ ...pageParams })
      ).content;
    }
    if (needSwitchArr.includes('human')) {
      data.humanRosterList = await getAllHumanRoster();
    }
    if (needSwitchArr.includes('position')) {
      data.positionList = await getPositionFlatList();
    }
    if (needSwitchArr.includes('positionType')) {
      data.positionTypeList = await getPositionTypeFlatList();
    }
    if (needSwitchArr.includes('positionHierarchy')) {
      data.positionHierarchyList = (
        await getPositionHierarchyList({ ...pageParams })
      ).content;
    }
    if (needSwitchArr.includes('job')) {
      data.jobList = (await GetJobList({ ...pageParams })).content;
    }
    if (needSwitchArr.includes('law')) {
      data.lawList = (await GetLegalEntityList({ ...pageParams })).content;
    }
    if (needSwitchArr.includes('workplace')) {
      data.workplaceList = (await GetWorkPlaceList({ ...pageParams })).content;
    }
    if (needSwitchArr.includes('contractType')) {
      data.contractTypeList = (
        await GetContractGroup({ ...pageParams })
      ).content;
    }
    if (needSwitchArr.includes('transactionType')) {
      data.transactionTypeList = await GetAllHumanChangeSetting();
    }
    return Promise.resolve(data);
  } catch (error) {
    console.log(error);
  }
};
